Skip to content

feat: add multivariate test case with keyed variants#57

Merged
gagantrivedi merged 1 commit into
mainfrom
feat/keyed-variant-test-case
Jun 8, 2026
Merged

feat: add multivariate test case with keyed variants#57
gagantrivedi merged 1 commit into
mainfrom
feat/keyed-variant-test-case

Conversation

@gagantrivedi

@gagantrivedi gagantrivedi commented Jun 8, 2026

Copy link
Copy Markdown
Member

Changes

Follow-up to #56. Every existing multivariate case in the corpus has variants without keys, so although the result schema now carries variant, nothing here exercises key passthrough — engines could fail to return a selected variant's key and still pass the corpus.

This adds one case where the variants carry stable keys and the identity is bucketed into a named variant, asserting its key is returned as variant:

"variants": [
  { "key": "variant_bar", "value": "bar", "weight": 30, "priority": 3402 },
  { "key": "variant_baz", "value": "baz", "weight": 30, "priority": 3404 }
]
// identity hashes into "baz" →
"result": { "flags": { "mv_feature": { "reason": "SPLIT; weight=30", "value": "baz", "variant": "variant_baz", ... } } }

The control bucket (variant: "control") and null cases are already covered by #56. The expected result was generated by running the engine, so it matches the real hashing/selection.

The existing multivariate cases have no variant keys, so nothing in the
corpus exercises key passthrough. Add a case where the variants carry
stable keys and the identity is bucketed into a named variant, asserting
its key is returned as `variant`.
@gagantrivedi gagantrivedi requested a review from a team as a code owner June 8, 2026 11:06
@gagantrivedi gagantrivedi requested review from emyller and removed request for a team June 8, 2026 11:06
@gagantrivedi gagantrivedi requested review from Zaimwa9 and removed request for emyller June 8, 2026 11:07
@gagantrivedi

Copy link
Copy Markdown
Member Author

/gemini review

gagantrivedi added a commit to Flagsmith/flagsmith-engine that referenced this pull request Jun 8, 2026
Every flag result now carries a `variant` field, mirroring OpenFeature's
`ResolutionDetails.variant` (always present, nullable):

- the variant's key when a named multivariate variant is selected,
- `"control"` when an identity falls in the control bucket (the leftover
  allocation that resolves to the feature's default value); the control is
  not a multivariate option, so the engine synthesises this key,
- `null` otherwise (standard features, unkeyed variants, or evaluation
  without an identity, where nothing is bucketed).

Selection logic, hashing and ordering are unchanged. The behaviour is
covered by the shared engine-test-data corpus; the submodule is pinned at
the keyed-variant branch (Flagsmith/engine-test-data#57) until released,
to be re-pinned to the tag.
@gagantrivedi gagantrivedi merged commit 5031065 into main Jun 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants